package com.heima.behavior.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.behavior.ApBehaviorEntryControllerApi;
import com.heima.behavior.service.ApBehaviorEntryService;
import com.heima.model.behavior.pojos.ApBehaviorEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/v1/behavior_entry")
public class ApBehaviorEntryController implements ApBehaviorEntryControllerApi {
    @Autowired
    private ApBehaviorEntryService apBehaviorEntryService;
    @GetMapping("/one")
    @Override
    public ApBehaviorEntry findByUserIdOrEquipmentId(@RequestParam("userId") Integer userId,@RequestParam("equipmentId") Integer equipmentId) {
        return apBehaviorEntryService.findByUserIdOrEquipmentId(userId,equipmentId);
    }
    // 查询粉丝实体Id
    @Override
    @PostMapping("findFansEntryId")
    public List findFansEntryId(@RequestBody List<Long> fansIdList) {

        return apBehaviorEntryService.list(
                Wrappers.<ApBehaviorEntry>lambdaQuery()
                        .eq(ApBehaviorEntry::getType, 1)    // 登录方式为 1  非设备登录
                        .in(ApBehaviorEntry::getEntryId, fansIdList)
        ).stream().map(m -> {
            return m.getId();
        }).collect(Collectors.toList());
    }
}